package com.zecan.blog.controller;

import com.alibaba.fastjson.JSON;
import com.zecan.blog.common.BlogResult;
import com.zecan.blog.service.ElasticService;
import com.zecan.blog.utils.BlogResultUtils;
import com.zecan.blog.vo.elasticsearch.ElasticArticleMsgVo;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.query.MatchAllQueryBuilder;
import org.elasticsearch.index.query.MatchQueryBuilder;
import org.elasticsearch.index.query.MultiMatchQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

/**
 * @ClassName ElasticSearchController
 * @Description
 * @date 2022/11/19 15:55
 * @Version 1.0
 */
@RequestMapping("/elasticsearch")
@RestController
public class ElasticSearchController {


    @Resource
    private ElasticService elasticService;


    /**
     * 根据关键字查询文章
     * @param keyWord
     * @return
     */
    @RequestMapping(value = "/searchKeyword",method = RequestMethod.POST)
    public BlogResult searchKeyWord(String keyWord) {

        ElasticArticleMsgVo articleByTitleAndDescription = elasticService.findArticleByTitleAndDescription(keyWord, 0, 10000);
        return BlogResultUtils.ok(articleByTitleAndDescription,"查询成功");
    }




}
